package org.busalerter.ui;

import ca.odell.glazedlists.gui.TableFormat;
import org.busalerter.domain.BusTime;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * Created by IntelliJ IDEA.
 * <p/>
 * User: bethella
 * Date: 18/11/11
 * Time: 17:12
 */
public class BusTimeTableFormat implements TableFormat<BusTime> {

    public int getColumnCount() {
        return 4;
    }

    public String getColumnName(int column) {
        if (column == 0) return "Route";
        else if (column == 1) return "Destination";
        else if (column == 2) return "ETA";
        else if (column == 3) return "Due Time";
     //   else if (column == 3) return "Alert";

        throw new IllegalStateException();
    }

    public Object getColumnValue(BusTime busTime, int column) {

        if (column == 0) return busTime.getRoute();
        else if (column == 1) return busTime.getDestination();
        else if (column == 2) return busTime.getEtaText();
     //   else if (column == 3) return busTime.getAlertText();
        else if (column == 3) {
            // calculate time due
            DateFormat dateFormat = new SimpleDateFormat("HH:mm");

            Calendar cal = new GregorianCalendar();
            cal.add(Calendar.MINUTE, busTime.getEtaMinutes());
            return dateFormat.format(cal.getTime());
        }

        throw new IllegalStateException();
    }
}

